﻿using System;
using BusinessObjects.Entities.Base;

namespace BusinessObjects.Entities
{
    public class PersonEntity : EntityBase<int>
    {
        public virtual string Name { get; set; }
        public virtual DateTime BirthDate { get; set; }
        public virtual AddressEntity Address { get; set; }

        public virtual bool Equals(PersonEntity other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }
            if (ReferenceEquals(this, other))
            {
                return true;
            }
            return Equals(other.Address, Address) && other.BirthDate.Equals(BirthDate) && other.Id == Id &&
                   Equals(other.Name, Name) && Equals(other.Timestamp, Timestamp);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }
            if (ReferenceEquals(this, obj))
            {
                return true;
            }
            if (obj.GetType() != typeof(PersonEntity))
            {
                return false;
            }
            return Equals((PersonEntity)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = (Address != null ? Address.GetHashCode() : 0);
                result = (result * 397) ^ BirthDate.GetHashCode();
                result = (result * 397) ^ Id;
                result = (result * 397) ^ (Name != null ? Name.GetHashCode() : 0);
                result = (result * 397) ^ (Timestamp != null ? Timestamp.GetHashCode() : 0);
                return result;
            }
        }

        public static bool operator ==(PersonEntity left, PersonEntity right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(PersonEntity left, PersonEntity right)
        {
            return !Equals(left, right);
        }
    }
}